﻿@model EvertonApp.AdminWeb.Models.ComercioModel

@{
    ViewBag.Title = "InicioComercio";
}

@*<div id="modalComercio"></div>

<div id="modalInternoComercio" class="modal hide fade">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button>
        <h3 id="myModalLabel">Modal header</h3>
    </div>
    <div class="modal-body">
        <input type="text" value="testeando" id="id1" />
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
</div>*@




@*<script type="text/javascript">
    jQuery('#modalInternoComercio').modal('show');
</script>*@

@*@using (Ajax.BeginForm("InsertarComercio", "Comercio", FormMethod.Post, new AjaxOptions { OnComplete = "limpiarCampos();", OnSuccess = "limpiarCampos();" }, new { @id = "formularioComercio", enctype = "multipart/form-data" }))
{

    <center>
     <div class="modal-body">
        <table  class="tabla_datos">
            <tr>
                <td>
                    @Html.Label("nombreLabel", "Nombre:")
                </td>
                <td>
                    @Html.TextBoxFor(mod => mod.Nombre, new { id = "Nombre", name = "NombreComercio", @Value = String.Empty } as object)
                </td>
                <td>
                    @Html.Label("telefonoLabel", "Teléfono:")
                </td>
                <td>
                    @Html.TextBoxFor(mod => mod.Telefono, new { id = "Telefono", name = "TelefonoComercio", @Value = String.Empty } as object)
                </td>
            </tr>    
            <tr>
                <td>
                    @Html.Label("direccionLabel", "Dirección:")
                </td>
                <td colspan="3">
                    @Html.TextBoxFor(mod => mod.Direccion, new { id = "Direccion", name = "DireccionComercio", style = "width: 100%;", @Value = String.Empty } as object)
                </td>
            </tr> 
            <tr>
                <td colspan="4" style="text-align:center">
                    <button type="submit" value="Insertar" id="btnInsertarComercio" class="btn btn-primary" >Insertar</button>
                </td>
            </tr>                
        </table>
    </div>*@

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <center><h4 class="modal-title">INSERCCIÓN COMERCIO</h4></center>
    </div>
    <div class="modal-body">
    <center>
     <div class="modal-body">
        <table  class="tabla_datos">
            <tr>
                <td>
                    @Html.Label("nombreLabel", "Nombre:")
                </td>
                <td>
                    @Html.TextBoxFor(mod => mod.Nombre, new { id = "Nombre", name = "NombreComercio", @Value = String.Empty } as object)
                </td>
            </tr> 
            <tr>
                <td>
                    @Html.Label("telefonoLabel", "Teléfono:")
                </td>
                <td>
                    @Html.TextBoxFor(mod => mod.Telefono, new { id = "Telefono", name = "TelefonoComercio", @Value = String.Empty } as object)
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("direccionLabel", "Dirección:")
                </td>
                <td colspan="3">
                    @Html.TextBoxFor(mod => mod.Direccion, new { id = "Direccion", name = "DireccionComercio", @Value = String.Empty } as object)
                </td>
            </tr>               
        </table>
    </div>
    </center>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-primary">Guardar</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
    </div>
    </div>
</div>
</div>


@using (Ajax.BeginForm("FiltroComercio", "Comercio", FormMethod.Post, new AjaxOptions { UpdateTargetId = "divGridComercios" }, new { @id = "formularioComercio", enctype = "multipart/form-data" }))
{ 
    
<center>
    <div>
        <table>
            <tr>
                <td>
                    Nombre @Html.TextBoxFor(mod => mod.Nombre, new { id = "Nombre", name = "NombreComercio", @Value = String.Empty } as object)
                </td>
                <td>
                    Dirección @Html.TextBoxFor(mod => mod.Direccion, new { id = "Direccion", name = "DireccionComercio", @Value = String.Empty } as object)
                </td>
                <td>
                    Teléfono @Html.TextBoxFor(mod => mod.Telefono, new { id = "Telefono", name = "TelefonoComercio", @Value = String.Empty } as object)
                </td>
                <td style="float:right">
                    <button type="submit" value="Filtrar" id="btnFiltrar" class="btn btn-primary" >Filtrar</button>
                </td>                
            </tr>
        </table>
    </div>
</center>
    
<center>
        <button type="button" class="btn btn-primary btn-large" onclick="funcion();">Insertar</button>
</center>
    
<center>
<div id="divGridComercios">
    @if (@Model.Comercios != null && @Model.Comercios.Count() > 0)
    {
        WebGrid grid = new WebGrid(defaultSort: "Nombre", rowsPerPage: 8);
        grid.Bind(Model.Comercios, autoSortAndPage: true, rowCount: Model.Comercios.Count());
        @grid.GetHtml(
            fillEmptyRows: false,
            tableStyle: "table table-striped table-bordered table-condensed",
            mode: WebGridPagerModes.All,
            //firstText: "<< Primera",
            //previousText: "< Anterior",
            //nextText: "Siguiente >",
            //lastText: "Última >>",
            columns: new[]{
                //grid.Column("IdComercio",header: "Nº Comercio", canSort: false),
                grid.Column("Nombre",header: "Nombre", canSort: false),
                grid.Column("Direccion",header: "Dirección", canSort: false),
                grid.Column("Telefono",header: "Teléfono", canSort: false), 
                grid.Column("",header: "Acciones", format:@<text>
                    @Ajax.ActionLink("Eliminar", "EliminarComercio", "Comercio", new { IdComercio = item.IdComercio }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divGridComercios" })
                    @Ajax.ActionLink("Editar", "EditComercio", "Comercio", new { IdComercio = item.IdComercio, Nombre = item.Nombre, Direccion = item.Direccion, Telefono = item.Telefono }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divGridComercios" })

                    </text> )}
        )
    }
    else
    {
        {@Html.Label("No se han encontrado comercios.")}
    }
</div>
</center>    
}


<script type="text/javascript">
    function funcion() {
        $('#myModal').modal('show');
    }
</script>